<!DOCTYPE html>
<html class="x-admin-sm">
	<head>
		<meta charset="UTF-8">
		<title>欢迎页面-X-admin2.2</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="stylesheet" href="../../css/font.css">
		<link rel="stylesheet" href="../../css/xadmin.css">
		<script type="text/javascript" src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="../../js/xadmin.js"></script>
		<script src="../../js/base.js" type="text/javascript" charset="utf-8"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row">
				
				<form class="layui-form" lay-filter="example">
					<div class="layui-form-item">
						
						<div class="layui-form-item">
							<label for="L_username" class="layui-form-label">
								<span class="x-red">*</span>日期</label>
							<div class="layui-inline" style="float: left;">
								<div class="layui-input-inline">
									<input type="text" id="date_text" name="date_text" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-input-inline">
								
								<button class="layui-btn select" lay-filter="select" lay-submit="">指标校验</button>
							</div>
						</div>
						<div class="layui-form-item">
							<label for="L_username" class="layui-form-label">
								<span class="x-red">*</span>指标代码</label>
							<div class="layui-input-inline">
								<input type="text" disabled="disabled" id="guide_code" disabled="disabled" name="guide_code" required=""
								 autocomplete="off" class="layui-input">
							</div>
							<label for="L_username" class="layui-form-label">
								<span class="x-red">*</span>指标名称</label>
							<div class="layui-input-inline">
								<input type="text" disabled="disabled" id="guide_name" name="guide_name" required="" autocomplete="off" class="layui-input">
							</div>
						</div>


						<div class="layui-form-item">
							<label for="L_username" class="layui-form-label">
								<span class="x-red">*</span>单月份指标SQL</label>
							<div class="layui-input-block">
								<textarea rows="" cols="" id="guide_sql" name="guide_sql" placeholder="请输入指标表达式" class="layui-textarea"></textarea>
							</div>
						</div>

						<div class="layui-form-item">
							<label for="L_username" class="layui-form-label">
								<span class="x-red">*</span>统计区间指标SQL</label>
							<div class="layui-input-block">
								<textarea rows="" cols="" id="guide_sql_sum" name="guide_sql_sum" placeholder="请输入指标表达式" class="layui-textarea"></textarea>
							</div>
						</div>



						<div class="layui-form-item">

							<div class="layui-input-inline">
								<label for="L_username" class="layui-form-label">
									<span class="x-red"></span></label>
								<button class="layui-btn select" lay-filter="save" lay-submit="">保存</button>
							</div>

						</div>
					</div>
				</form>
			</div>
		</div>
		<script>
			layui.use(["form", "layer", "laydate"],
				function() {
					$ = layui.jquery;
					var form = layui.form,
						layer = layui.layer;
					laydate = layui.laydate;

					laydate.render({
						elem: '#date_text',
						type: 'month'
					});

					var guide_code = get("guide_code");

					$.post(root + "Zhibiaoweihu/get_expressions", {
							guide_code: guide_code
						},
						function(data) {

							form.val("example", data.data);
						}
					);


					form.on('select(isexpress)', function(adata) {
						var value = adata.value;
						if (value == 0) {
							$("#guide_express").val("");
							$("#guide_express").attr("disabled", true);
						}
						if (value == 1) {
							$("#guide_express").attr("disabled", false);
						}
					});

					//监听提交
					form.on("submit(save)",
						function(data) {
							console.log(data.field);

							$.post(root + "Zhibiaoweihu/save_expressions",
								data.field,
								function(data) {
									if (data.code == 0) {
										layer.alert(data.msg, {
											icon: 6
										});
										xadmin.close();
										xadmin.father_reload();
									} else {
										layer.alert(data.msg, {
											icon: 2
										});
									}
								});

							return false;
						});
					
					form.on("submit(select)",
						function(data) {
							console.log(data.field);
					
							var date = $("#date_text").val();
							
							$.post(root + "Zhibiaoweihu/create_data", {
									date:date,
									guide_code: guide_code
								},
								function(data) {
									xadmin.open("指标校验","create_list.html?guide_code="+guide_code+"&date="+date,800,600)
									//form.val("example", data.data);
								}
							);
					
							return false;
						});
					
					form.on('select(account_dept_code)', function(data) {
						console.log($("#account_dept_code").find("option:selected").text());
						$("#account_dept_name").val($("#account_dept_code").find("option:selected").text());
					});
					
					
				});
				
				function select()
				{
					var date = $("#date_text").val();
					
					$.post(root + "Zhibiaoweihu/create_data", {
							date:date,
							guide_code: guide_code
						},
						function(data) {
							
							console.log(1);
							
						}
					);
					
				}
		</script>
		<script>
			var _hmt = _hmt || [];
			(function() {
				var hm = document.createElement("script");
				hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
				var s = document.getElementsByTagName("script")[0];
				s.parentNode.insertBefore(hm, s);
			})();
		</script>
	</body>

</html>
